/* 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Title : com.Angaliwa.Theme
Author : Dave Jansen -- Zenitum
URL : http://www.zenitum.com/

Description : The Theme library allows you to easily apply
			  themes and theme-related functionality to
			  your project(s). 

Created : May 27th, 2009

Version: 1.0
Compatibility: 1.0

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
*/

package com.Angaliwa
{
	public class Theme
	{
		import mx.events.FlexEvent;
		
		public var daisyChain:Object = [];
	    
		/*
		 * Summary:      	Set the current theme.
		 * Return:       	Void
		 * Version:   	 	1.0
		 * Compatibility:	1.0
		 */
		public function setTheme(o:Object, t:Object=null, f:Function=null):void {
			this.runDaisyChain('beforeSetTheme', new Array(o,t,f));
			
			if(t != null) o.selectedChild = t;
				else o.selectedIndex = 0;
			
			this.runDaisyChain('afterSetTheme', new Array(o,t,f));
			
			if(f != null) t.addEventListener(FlexEvent.INITIALIZE, f);
		}
        
        /*
		 * Summary:      	Executes specific daisy chain actions (if
		 					available).
		 * Return:       	Boolean
		 * Version:   	 	1.0
		 * Compatibility:	1.0
		 */
        private function runDaisyChain(func:String, obj:Object=undefined):Boolean {
        	try{	
        		this.daisyChain[func](obj);
        		return true;
        	} catch(Error:*){
        		return false;
        	}
        	
        	return true;
        }
	}
}